/*
*    Phantom v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#pragma once
//#include "PhantomBase.h"

#include "SSI_ScriptAPI.h"

#define SSI_PHANTOM_API __declspec(dllexport)

#ifndef __DATANODE
typedef struct WinDataT* DataNode;
#define __DATANODE
#endif //__DATANODE

#ifndef __WINDATAT
#define __WINDATAT
struct WinDataT{
	String* WinName;
	String* WinTag;
	String* WinClass;
	String* WinType;
	int iWinTag;
	int IsParent;
	int IsChild;
	DataNode Next;
	DataNode Prev;
	DataNode Parent;
	DataNode FChild;
};
#endif //__WINDATAT

class CDataBitmap;
class CWindowChecker;
class CBitmap;
class CDC;
class CWnd;
class CPalette;
class CSize;

class SSI_PHANTOM_API CDataWindow :
	public CData
{

protected:
	virtual SSI_BOOL CopyData(CData* Other);
private:
	virtual CData* MakeData(void);
public:
	virtual SSI_BOOL DeleteData(CData* In);  // Not pure yet, but still must be made pure
	virtual SSI_BOOL DataFromString(const String& sData);
	virtual String GetString();
  virtual SSI_INT64 SizeOf();
	virtual SSI_INT64 Register(SSI_INT64 NewType);
	virtual void UnRegister();
	virtual CData* operator_equal(CData* InData, OpInfoT* Info = SSI_NULL);
  virtual SSI_BOOL boolean();
	//virtual CStatus EvalClass(VarItor InVar, VarTree& InTree, CStatement& aStat);

public:
	CDataWindow(void);
	virtual ~CDataWindow(void);
private:
	static SSI_INT64 sType;

public:
	String WinName;
	String WinTag;
	String WinClass;
	String WinType;
	SSI_INT64 iWinTag;

	VarTree LocVarSet;

public:
	CStatus FindMe(UINT& Val, HMENU& hMenu);
	CStatus GetText(String& Ret);
	CStatus SetText(String& Set);
	virtual CStatus InitData(void);
	virtual void SSI_FunctionProcessor(SSI_FunctionAPI& theAPI);
	virtual CStatus SSI_UpdateVariable(CVariable& aVar, SSI_BOOL bGet);
	static SSI_INT64 GetRegisteredType(void);
	virtual CStatus AddLocalVariable(CData* InData, String& Name);
	void ListToScreen(CEngine* anEng, SSI_INT64 InLevel);
	bool ConstructChildPath(CDataWindow* Child);
	String GetPathString();
protected:
	DataNode Path;
public:
	void Internal_FunctionProcessor(SSI_FunctionAPI& theAPI, HWND hWin, String& Class);

protected:
	HWND FindPartialWindow(HWND Par, HWND Child, String& Class, String& Tag, BOOL PartClass, BOOL PartTag);
	HWND FindNumericWindow(HWND Par, String& inClass, SSI_INT64 iTag, BOOL PartClass);
public:
	static CStatus SetDelay(int newDelay);
	static SSI_INT64 iDelay;
	HWND FindMenu(HWND Par, DataNode CurrNode, UINT& Val, HMENU& hMenu);
	HWND myWin;
  HWND setWin;
	CStatus PostMessage(UINT Cmd, WPARAM wParam, LPARAM lParam);
	CStatus CaptureBitmap(CDataBitmap& Ret);

	//HANDLE DDBToDIB(CBitmap &bitmap, DWORD dwCompression, CPalette *pPal, int &Offset);
	char* DDBToDIB(CBitmap &bitmap, DWORD dwCompression, CPalette *pPal, BITMAPINFOHEADER &bi, int &Offset);
	BOOL WndToBmp(CDC *pDC, CSize cbImage, CDataBitmap& Ret);

	virtual CStatus AddFunction(CFunctionDecl& NewFunc, String& CurrClass);
	String GetClass(HWND hWin);

	CStatus MouseClick(CWnd* aWin, int iButton, int X, int Y, int iType);
	CStatus TypeKeys(CWnd* aWin, String& inKeys);
	CStatus TypeKeys2(CWnd* aWin, String &InParams, UINT Type);
	UINT GetKeyCode(String& Line);
	CStatus TypeKeysEx(String& InParams);
	int IsShifted(char c);

  DataNode CreatePathTree(void);
  int InitializeFromWindow(const CWnd* In);
  SSI_BOOL IsLocalClass(const String& ClassName);
	void DoDelay(void);

  void SendKey(UINT Code, UINT ScanCode, DWORD Flag1, DWORD Flag2);
};

CStatus LoadDecNodes(File& InFile, DataNode &CurrNode);
void DelDataNodeTree(DataNode winNode);
CStatus AddNewWindows(DataNode CurrNode, CEngine* theEngine);

CStatus AddChildren(DataNode CurrNode, CDataWindow* ParWin, CEngine* theEngine);
DataNode CopyPath(DataNode Original);
DataNode GetFreshNode(DataNode Ret);
CStatus FindFile(String& Dir, String &InFile, String &OutFile);